//
//  LXCareViewController.m
//  喜马拉雅改良版框架
//
//  Created by liuxin on 15/12/29.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LXCareViewController.h"
#import "LXCareTableViewCell.h"
@interface LXCareViewController ()<UITableViewDataSource,UITableViewDelegate,LXCareModelDelegate>
@property(nonatomic,strong)UITableView *myTableView;
@property(nonatomic,strong)NSMutableArray *allArray;
@end

@implementation LXCareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.allArray = [NSMutableArray array];
    self.view.backgroundColor = [UIColor whiteColor];
    [self getData];
    [self createTableView];
}
-(void)getData{
    NSString *urlStr = @"http://mobile.ximalaya.com/mobile/api/1/feed/unlogin/dynamic?device=iPhone";
    [AFNetworkTool getUrl:urlStr body:nil result:HXJSON headerFile:nil success:^(id result) {
        NSArray *array = result[@"data"];
        for (NSDictionary *dic in array) {
            LXCareModel *temp = [LXCareModel new];
            [temp setValuesForKeysWithDictionary:dic];
            CGSize labelSize = [AppTools labelRectWithLabelSize:CGSizeMake(SCREEN_WIDTH-100, 10000) LabelText:temp.trackTitle Font:[UIFont systemFontOfSize:15]];
            temp.height = labelSize.height;
            [self.allArray addObject:temp];
        }
        [self.myTableView reloadData];
    } failure:^(NSError *error) {
    }];
}
-(void)createTableView{
    self.myTableView = [[UITableView alloc]init];
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.offset(0);
        make.height.mas_equalTo(SCREEN_HEIGHT-65);
    }];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.myTableView registerClass:[LXCareTableViewCell class] forCellReuseIdentifier:@"cell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _allArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    view.backgroundColor = [UIColor colorWithWhite:0.835 alpha:1.000];
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:view.bounds];
    titleLabel.text = @"   推荐关注";
    titleLabel.textColor = [UIColor grayColor];
    [view addSubview:titleLabel];
    return view;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LXCareTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.backgroundColor = [UIColor colorWithWhite:0.835 alpha:1.000];
    cell.careModelDelegate = self;
    cell.cellModel = [_allArray objectAtIndex:indexPath.row];
    return cell;
}
-(void)bringIDtoViewController:(NSString *)str ID:(NSInteger)ID Image:(NSString *)Image Title:(NSString *)title{
    if ([str isEqualToString:@"play"]) {
        LXMusicPlayerVC *music = [LXMusicPlayerVC new];
        music.songId = ID;
        music.headImageLarge = Image;
        music.Title = title;
        [self presentViewController:music animated:YES completion:nil];
    }else{
        LXAuthorTableVC *author = [LXAuthorTableVC new];
        author.Uid = [NSString stringWithFormat:@"%ld",ID];
        [self.navigationController pushViewController:author animated:YES];
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
